import time

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys

class Base:
    # 初始化
    def __init__(self,driver):
        self.driver = driver
    # 封装url
    def url_open(self,loc):
        self.driver.get(loc)
    # 定位
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as p:
            self.driver.save_screenshot("jieping.png")
            print(p)
    # 点击
    def click(self,loc):
        self.driver.find_element(loc).click()
    # 输入文本
    def send_keys(self,loc,info):
        self.driver.find_element(loc).send_keys(info)
    # 提取文本
    def text(self, loc):
        return self.driver.find_element(loc).text
    # 隐式等待
    def implicitly(self,loc):
        self.driver.implicitly_wait(int(loc))
    # 显示等待
    def sellp(self,info):
        time.sleep(int(info))
    # 滚动条

    # 弹框处理

    # iframe处理

    # 切换页面，
    def qhym(self):
        self.driver.switch_to.window(self.driver.current_window_handle[-1])
    # 鼠标事件，
    def click1(self, loc):
        self.driver.find_element(loc).click()
    # 键盘事件，
    def enter(self,loc):
        self.driver.find_element(loc).send_keys(Keys.ENTER)
    # 浏览器事件，
    def quit(self):
        self.driver.quit()
    # 下拉框选择



